package ragserverengine.neo4j.core

import org.neo4j.driver.AuthTokens
import org.neo4j.driver.GraphDatabase
import org.neo4j.driver.*


class Neo4jClient(
    private val url: String = "bolt://10.10.1.166:7689",
    private val user: String = "neo4j",
    private val password: String = "Aa123456"
) {

    private lateinit var driver: Driver


    // 连接
    fun conllect() {

        driver = GraphDatabase.driver(url, AuthTokens.basic(user, password))
        println("Connected to Neo4j at $url")

    }

    fun isConnected(): Boolean {
        return ::driver.isInitialized
    }


    /** 获取 Driver */
    fun getDriver(): Driver {
        if (!isConnected()) {
            throw IllegalStateException("Neo4j driver not connected.")
        }
        return driver
    }

    /** 关闭连接 */
    fun close() {
        if (::driver.isInitialized) {
            driver.close()
            println("Neo4j connection closed.")
        }
    }


}